package day10;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        double[][] points = new double[3][2];
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入三角形三个点的坐标：");
        for(int i = 0;i < 3;i++){
            points[i][0] = scanner.nextDouble();
            points[i][1] = scanner.nextDouble();
        }
        double flag = getTriangleArea(points);
        if(flag == 0){
            System.out.println("The three points are on the same line");
        }else{
            System.out.println("The area of the triangle is " + flag);
        }

    }
    public static double getTriangleArea(double[ ][ ] points){
        double k01 = 0,k02 = 0,b01 = 0,b02 = 0;
        k01 = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]);
        k02 = (points[2][1] - points[0][1]) / (points[2][0] - points[0][0]);
        b01 = points[0][1] - k01 * points[0][0];
        b02 = points[0][1] - k02 * points[0][0];
        if(k01 == k02 && b01 == b02){
            return 0;
        }
        double side1 = Math.sqrt(Math.pow(points[1][0] - points[0][0],2) + Math.pow(points[1][1] - points[0][1],2));
        double side2 = Math.sqrt(Math.pow(points[2][0] - points[0][0],2) + Math.pow(points[2][1] - points[0][1],2));
        double side3 = Math.sqrt(Math.pow(points[2][0] - points[1][0],2) + Math.pow(points[2][1] - points[1][1],2));
        double s = (side1 + side2 + side3) / 2;
        return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
    }
}